//  ========== 
//  = 我的借款产品列表 业务JS = 
//  ==========
var page = 1;
var limit = 8;
var Main = function(){
	mui.init({
		swipeBack:true 		//启用右滑关闭功能
	});
	this.init();
	this.loadData(page);
};
Main.prototype = {
	init : function(){
		mui('.mui-scroll-wrapper').scroll({
					indicators: true //是否显示滚动条
		});
		var _this = this;
		mui.each(document.querySelectorAll('.mui-slider-group .mui-scroll'), function(index, pullRefreshEl) {
		mui(pullRefreshEl).pullToRefresh({
			down: {
				callback: function() {
				   var self = this;
				   page = 1;
					_this.proj(index,page,function(){
						_this._prodBindTap()
						self.endPullDownToRefresh();
					});
				}
			},
			up: {
				callback: function() {
					var self = this;
					_this.proj(index,++page,function(){
						_this._prodBindTap();
						self.endPullUpToRefresh();
					});

				}
			}
		});
					});
					
		var _this = this;
		
		_this.eventInit()
		
	},
	eventInit : function(){//绑定事件
		var _this = this;
        //标为全读
			$('.m-set-read').on('tap',function(){
				//获得所有需要标记id
				var ids= '';
				$('.m-not-state-read').each(function(){
					if(ids == ''){
						ids = this.getAttribute('data-id');
					}else{
						ids += ','+this.getAttribute('data-id');
					}
				});
				if(ids != ''){
					//询问框
				  layer.open({
				    content: '您确定要标记为全读？'
				    ,btn: ['确定', '取消']
				    ,yes: function(index){
				      layer.close(index);
				      layer.open({type: 2});
				      var param = {
								ids:ids,
								state:"1"
								};

				      $.post(server_url +'/message/isUpdateOaNewsMessage.do',param,function(data){
				      	$(".m-not-state-read").removeClass('m-not-state-read');
				      	$(".m-not-state-read").addClass('m-state-read');
				       layer.closeAll()
				      })
				      
				    }
				  });
				}
				 
			})	
        
	},
	_itemBindTap : function(){//列表绑定点击事件
			mui(".m-msg").on('tap','li',function(){
				mui.openWindow({
					    url:'myMessageDetail.html?id='+this.getAttribute('data-id'),
					    id:'myMessageDetail'
				     }
				);
			});
			
		
	},

	//内容列表
	loadData : function(page,_callback){
		var _this = this;
		var param = {
				isMobile:1,
				memberId:Util.getLoginUser().memberId,
				page:page,
				limit:limit
				};
		var url = server_url+'/message/getUserAllOaNewsMessage.do';
		$.getJSON(url,param  ,function(data){
			var _html = '';
			if(data.success){
	           for(var i=0;i<data.result.length;i++){
	            	var item = data.result[i];
					_html += '\n <li class="mui-table-view-cell '+('1'==item.readStatus?'m-state-read' :'m-not-state-read')+'" data-id="'+item.id+'">';
					_html += '\n <a class="mui-navigate-right">';
					_html += '\n <div class="m-msg-tit mui-ellipsis">';
					_html += item.title;
					_html += '\n <i class="m-msg-state"></i>';
					_html += '\n </div>';
					_html += '\n <div class="m-msg-time">'+item.sendTime+'</div>';
					_html += '\n </a>';
					_html += '\n <div class="m-msg-des mui-ellipsis">'+item.content+'</div>';
				    _html += '\n </li>';
					}	
            	
            }			
            if(page == 1){
            	$('.m-msg').html('');
            }
			_this._itemBindTap();
             $('.m-msg').append(_html);
             
             if($.isFunction(_callback)){
             	_callback();
             }
		});
	}
	
}
